package cn.swh.guguanjia.controller;

import cn.swh.guguanjia.entity.AppVersion;
import cn.swh.guguanjia.entity.Result;
import cn.swh.guguanjia.service.AppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

//app管理
@RestController
//manager/app/index   对应列表页请求
@RequestMapping("/mapper/app")
public class AppVersionController {
    @Autowired
    AppVersionService service;

    @RequestMapping("")
    public ModelAndView index(){
        return new ModelAndView("/app/index.html");
    }

    @RequestMapping({"/toUpdate", "/update.html"})
    public ModelAndView toUpdate() {
        return new ModelAndView("/app/update.html");
    }

    @RequestMapping(value = "doUpdate", method = RequestMethod.POST)
    public Result doUpdate(@RequestBody AppVersion app) {
        return new Result(service.updateByPrimaryKeySelective(app));
    }


    @RequestMapping("index")
    public Result listAll() {
//        int a=1/0;
        return new Result(service.selectAll());
    }


    //app
    @RequestMapping("selectPage/{pageNum}/{pageSize}")
    public Result selectPage(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize) {
        return new Result(service.selectPage(pageNum, pageSize));
    }

    //添加
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public Result insert(@RequestBody AppVersion app) {
        app.setCreateDate(new Date());
        app.setUpdateDate(new Date());
        app.setDelFlag("0");
        return new Result(service.insertSelective(app));
    }


}
